<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="../../Templates/SubFolderTemplate.xhtml"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core">
    
    <ui:define name="head-title">
        <title>Add Customer Invoice | Merlion's ERP System</title>
    </ui:define>
    
    <ui:define name="content">
        <f:view beforePhase="#{addCustomerInvoiceManagerBean.initView(event)}">
            <h:form prependId="false">
            <p:panel id="panel" header="Create an Invoice for Customer"> 
                <p:ajaxStatus style="width:16px;height:16px;">   
                    <f:facet name="start">   
                        <p:graphicImage value="http://www.primefaces.org:8080/showcase/design/ajaxloading.gif" /> 
                    </f:facet> 
 
                    <f:facet name="complete">   
                        <h:outputText value="" />   
                    </f:facet>   
                </p:ajaxStatus> 
            
                <p:messages /> 
                
                <p:fieldset legend="Customer Account Information">
                <h:panelGrid columns="3" cellpadding="2"> 
                    
                    <h:outputLabel for="saleLeadName" style="font-weight: bold" value="Company Name: " />
                    <h:outputText value="#{addCustomerInvoiceManagerBean.customer.saleLeadName}" id="saleLeadName"/>
                    <p:message for="saleLeadName" /> 
                    
                    <h:outputLabel for="saleLeadId" style="font-weight: bold" value="Registration Number: " />
                    <h:outputText value="#{addCustomerInvoiceManagerBean.customer.registrationNumber}"  id="saleLeadId"/>
                    <p:message for="saleLeadId" /> 
                    
                    <h:outputLabel for="creditLimit" style="font-weight: bold" value="Credit Limit: " />
                    <h:outputText value="#{addCustomerInvoiceManagerBean.customer.creditAccount.creditLimit}" id="creditLimit"/>
                    <p:message for="creditLimit" /> 
                    
                    <h:outputLabel for="outstandingCredit" style="font-weight: bold" value="Outstanding Credit: " />
                    <h:outputText value="#{addCustomerInvoiceManagerBean.customer.creditAccount.outstandingCredit}" id="outstandingCredit"/>
                    <p:message for="outstandingCredit" /> 
                    
                    <h:outputLabel for="creditBalance" style="font-weight: bold" value="Credit Balance: " />
                    <h:outputText value="#{addCustomerInvoiceManagerBean.customer.creditAccount.creditBalance}" id="creditBalance"/>
                    <p:message for="creditBalance" />                     
                </h:panelGrid>
                    
                </p:fieldset>
                
                <br></br>
                <p:fieldset legend="Sale Order Information">
                    
                
                <h:panelGrid columns="3" cellpadding="3"> 
                    
                    <h:outputLabel for="saleOrderId" style="font-weight: bold" value="Sale Order ID: " />
                    <h:outputText value="#{addCustomerInvoiceManagerBean.selectedDeliveryOrder.saleOrder.id}"  id="saleOrderId"/>
                    <p:message for="saleOrderId" /> 
                    
                    <h:outputLabel for="saleOrderDate" style="font-weight: bold" value="Sale Order Date: " />
                    <h:outputText value="#{addCustomerInvoiceManagerBean.selectedDeliveryOrder.saleOrder.saleOrderDate}" id="saleOrderDate"/>
                    <p:message for="saleOrderDate" /> 
                    
                    <p:dataTable var="lineItem" value="#{addCustomerInvoiceManagerBean.selectedDeliveryOrder.saleOrder.lineItems}"
                              emptyMessage="No Line Items" style="width: 50%;">
                    <p:column sortBy="#{lineItem.productPrice.productType}">
                        <f:facet name="header">
                            <h:outputText value="Product Type"/>
                        </f:facet>
                        <h:outputText value="#{lineItem.productPrice.productType}"/>
                    </p:column>

                    <p:column>
                        <f:facet name="header">
                            <h:outputText value="Quantity"/>
                        </f:facet>
                        <h:outputText value="#{lineItem.lineItemQuantity}" style="width: 150px"/>
                    </p:column>
                    
                     <p:column>
                        <f:facet name="header">
                            <h:outputText value="Price per Unit"/>
                        </f:facet>
                         <h:outputText value="#{lineItem.productPrice.productPrice}" style="width: 150px"/>
                    </p:column>
                    
                    <p:column>
                        <f:facet name="header">
                            <h:outputText value="Volume Discount(%)"/>
                        </f:facet>
                        <h:outputText value="#{lineItem.volumeDiscountRate}" style="width: 150px"/>
                    </p:column>
                    
                    <p:column>
                        <f:facet name="header">
                            <h:outputText value="Final Price"/>
                        </f:facet>
                        <h:outputText value="#{lineItem.finalPrice}" style="width: 150px"/>
                    </p:column>
                    
                        <f:facet name ="footer">
                        <h:outputText value="Total Price: "/>
                        <h:outputText value ="#{addCustomerInvoiceManagerBean.selectedDeliveryOrder.saleOrder.totalPrice}"/>
                    </f:facet>
                    </p:dataTable>
                </h:panelGrid>
                    
            </p:fieldset>
                
                <br></br>
                
                <p:fieldset legend="Delivery Order Information">
                

                <h:panelGrid columns="3" cellpadding="2"> 
                    
                
                    <h:outputLabel for="deliveryOrderId" style="font-weight: bold" value="Delivery Order ID: " />
                    <h:outputText value="#{addCustomerInvoiceManagerBean.selectedDeliveryOrder.id}"  id="deliveryOrderId"/>
                    <p:message for="deliveryOrderId" /> 
                    
                    <h:outputLabel for="deliveryOrderDate" style="font-weight: bold" value="Delivery Order Date: " />
                    <h:outputText value="#{addCustomerInvoiceManagerBean.selectedDeliveryOrder.deliveryDate}"  id="deliveryOrderDate"/>
                    <p:message for="deliveryOrderDate" /> 
                
                    
                    <p:dataTable var="productLine" value="#{addCustomerInvoiceManagerBean.selectedDeliveryOrder.productLines}"
                             emptyMessage="No Product Line" style="width: 50%;">
                    <p:column>
                        <f:facet name="header">
                            <h:outputText value="Product Type"/>
                        </f:facet>
                        <h:outputText value="#{productLine.product.productType}"/>
                    </p:column>

                    <p:column>
                        <f:facet name="header">
                            <h:outputText value="Quantity"/>
                        </f:facet>
                        <h:outputText value="#{productLine.quantity}" style="width: 150px"/>
                        </p:column>
                    
                 <p:column>
                        <f:facet name="header">
                            <h:outputText value="Final Price"/>
                        </f:facet>
                     <h:outputText value="#{productLine.finalPrice}" style="width: 150px"/>
                    </p:column>
                    
                    <f:facet name ="footer">
                        <h:outputText value="Total Price: "/>
                        <h:outputText value ="#{addCustomerInvoiceManagerBean.selectedDeliveryOrder.totalPrice}"/>
                    </f:facet>
                    </p:dataTable>
                </h:panelGrid>
                    
            </p:fieldset>
                    
                <br></br>

            <p:fieldset legend="Summary">
                <h:panelGrid columns="3" cellpadding="4" > 
                    
                    <h:outputLabel for="beforeSettlement" style="font-weight: bold" value="Before Settlement: " />
                    <h:outputText value="#{addCustomerInvoiceManagerBean.selectedDeliveryOrder.totalPrice}"  id="beforeSettlement"/>
                    <p:message for="beforeSettlement" />                     
                
                    <h:outputLabel for="cashInAdvanceAmount" style="font-weight: bold" value="Cash in advance amount (if any): " />
                    <h:outputText value="#{addCustomerInvoiceManagerBean.selectedDeliveryOrder.saleOrder.cashInAdvance != null ? addCustomerInvoiceManagerBean.selectedDeliveryOrder.saleOrder.cashInAdvance.cashInAdvanceAmount : 'Not applicable'}"  id="cashInAdvanceAmount" />
                    <p:message for="cashInAdvanceAmount" />                     
                                        
                    <h:outputLabel for="afterSettlement" style="font-weight: bold" value="After Settlement: " />
                    <h:outputText value="#{addCustomerInvoiceManagerBean.finalAmount}"  id="afterSettlement"/>
                    <p:message for="afterSettlement" />                     
                </h:panelGrid>
            </p:fieldset>
                
                    
                </p:panel>
                <p:commandButton id="btn" value="Confirm Invoice" update="panel" actionListener="#{addCustomerInvoiceManagerBean.saveNewCustomerInvoice(event)}" ajax="false" />
            
        </h:form>
      </f:view>
    </ui:define>
</ui:composition>

